function autoAddDictionary (type, props) {
  switch (type) {
  case 'state':
    return props;
  case 'mutations':
    let step = {};
    for (let index in props) {
      if (props.hasOwnProperty(index)) {
        step['SET_' + index] = function (state, payload) {
          state[index] = payload;
        };
      }
    }
    return step;
  case 'getters':
    return {
      dictionary: state => {
        let step = {};
        for (let index in props) {
          if (props.hasOwnProperty(index)) {
            let keyMap = {};
            for (let item of state[index]) {
              keyMap[item.dictionaryid + ''] = item.value;
            }
            step[index] = keyMap;
          }
        }
        return step;
      },
    };
  }
}

function autoVueXPre (type, data, name) {
  const modelName = name.toUpperCase();
  let step = {};
  switch (type) {
  case 0:
    autoVueXPreInner(modelName + '_', function (index) {
      return data[index];
    });
    break;
  case 1:
    autoVueXPreInner('GET_' + modelName + '_', function (index) {
      return data[index];
    });
    break;
  case 2:
    autoVueXPreInner('SET_' + modelName + '_', function (index) {
      return function (state, payload) {
        state[modelName + '_' + index] = payload;
      };
    });
    break;
  case 3:
    autoVueXPreInner('USE_' + modelName + '_', function (index) {
      return data[index];
    });
    break;
  }
  function autoVueXPreInner (preName, value) {
    for (let index in data) {
      if (data.hasOwnProperty(index)) {
        step[preName + index] = value(index);
      }
    }
  }
  return step;
}
export {
  autoAddDictionary,
  autoVueXPre, // VueX Store 自动前缀 核心
};
